package com.myqm.service.impl.sys;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary; 
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.myqm.dao.sys.SysLogsDao;
import com.myqm.pojo.sys.SysLogs;
import com.myqm.service.sys.SysLogsService; 
@Primary
@Service 
public class SysLogsServiceImpl implements SysLogsService { 
	@Autowired
	private SysLogsDao sysLogsDao;
	 
	@Override
	public Integer save(SysLogs sysLogs) {
//		SysUser User = UserUtil.getLoginUser();
//		if (User == null || User.getId() == null) {
//			return -5L;
//		} 
		sysLogs.setUserId(1);
		sysLogsDao.save(sysLogs);
		return sysLogs.getId();
	} 
 
	@Override
	public int save(Integer userId, String module, Boolean flag, String remark) {
		SysLogs sysLogs = new SysLogs();
		sysLogs.setFlag(flag);
		sysLogs.setModule(module);
		sysLogs.setRemark(remark);

//		SysUser User = UserUtil.getLoginUser(); 
		sysLogs.setUserId(1);

		return  sysLogsDao.save(sysLogs); 
	}

	@Override
	public int delMonthLogs(int year, int start, int end) {  
		int n = sysLogsDao.deleteLogs(year, start, end); 
		return n;
	}
	 
	public int deleteLogs() {  
		 System.out.println("delete log");
		return 2;
	}
   
 
	public Integer delById(Integer id) { 
		if( sysLogsDao.delById(id)>0)
			return id;
		else
			return -1;
	}
  
 
	public SysLogs getById(Integer id) {
		return (SysLogs) sysLogsDao.getById(id);
	}
 
 
	public Integer edit(SysLogs record) { 
		 
		if( sysLogsDao.editById(record)>0)
			return record.getId();
		else
			return -1; 
	}
 
	public List<Integer> delAll(List<Integer> list) {
		List<Integer> result = new ArrayList<Integer>();
		for(int i = 0; i < list.size(); i++)
		{
			if ( sysLogsDao.delById(list.get(i)) > 0) 
				result.add(list.get(i)); 
		} 
		return result;
	}
 
	public PageInfo<SysLogs> listBrif(int pagenum, int pagesize) {
		PageHelper.startPage(pagenum, pagesize);
		List<SysLogs> datalist = sysLogsDao.listBrif();
	 	PageInfo<SysLogs> p = new PageInfo<SysLogs>(datalist); 
		return p;
	}

	@Override
	public PageInfo<SysLogs> list(int pagenum, int pagesize) {
		PageHelper.startPage(pagenum, pagesize);
		List<SysLogs> datalist = sysLogsDao.listBrif();
	 	PageInfo<SysLogs> p = new PageInfo<SysLogs>(datalist); 
		return p;
	}

	@Override
	public List<SysLogs> listAllBrif() {
		List<SysLogs> datalist = sysLogsDao.listBrif(); 
		return datalist;
	}
	 
 
}
